(function($) {
	function jText(element, handle, img) {
		this.element = element;
		this.handle = handle;
		this.img = img;
		this.borderColor = $(element).css("borderColor");

		this.fieldTemplate = "<div class=\"x-form-field\"></div>";
		this.imgTemplate = "<img src=\"s.gif\" class=\"x-form-date-img\" align=\"top\">";

		this.imgwht = 2;
		

		

		this._init = function() {
			var element = this.element;
			var $element = $(element);

			$element.after(this.fieldTemplate);

			field = $element.next(".x-form-field");

			$field = $(field).append($element);
			
			var fw = 0;
			if (!$.browser.msie) {
				fw = this.imgwht;
			}
			$field.css({width:$element.outerWidth() - fw});

			$img = $(this.imgTemplate).appendTo($field);
			var _img = this.img;
			if (_img != null) {
				if (_img.indexOf("url") == -1) 
					_img = "url(" + _img + ")";

				$img.css("backgroundImage", _img);
			}

			
			$element.focus(function(){
					if (!$element.attr("readonly"))
						$(this).parent().addClass("x-form-field-focus");
				})
				.blur(function(){
					if (!$element.attr("readonly"))
						$(this).parent().removeClass("x-form-field-focus");
				});

			$element.addClass("x-form-text")
					.css({width:$element.outerWidth() - $img.outerWidth() - this.imgwht});
			


			$img.click(function() {
				if (!$element.attr("disabled"))
					handle.call(this, element);
			});

		}
		
		this._init();
	}

	$.fn.extend({
		jtext: function(handle, img) {
			return this.each(function() {
				//alert(this.id + "@@" + $(this).css("borderColor"));
				if (this.nodeName.toLowerCase() == "input" && this.type == "text") {
					new jText(this, handle, img);
				}
				
			});
		}
	});
})(jQuery);
